﻿<%--
///////////////////////////////////////////////////////////////////////////
/// File: <FileName>
/// Description: 
///    <Description>
/// Copyright© <DateTime.Now.Year> <Copyright>
/// History:
///     <DateTime.Now>    My.GenCode    Original Version
///////////////////////////////////////////////////////////////////////////
--%>
<%@ Page Language="C#" Inherits="<<NameSpace>>.Web.BasePage" AutoEventWireup="false" %>
<%@import namespace="System" %>
<%@import namespace="System.Threading" %>
<%@import namespace="System.Collections.Generic" %>
<%@import namespace="<<NameSpace>>.Domain.Entities" %>
<%@import namespace="<<NameSpace>>.Domain.Interfaces" %>
<%@import namespace="<<NameSpace>>.Business.Security" %>
<%@import namespace="<<NameSpace>>.Web.Controllers" %>
<script runat="server">
</script>
<%
    <<HandlerClassName>> _this = new <<HandlerClassName>>(this);
    
    MAF.Common.PageInfo page;
    IList<<<EntityClassName>>> list = _this.<<ReadListMethodName>>(out page);

%>


<form id="Frm<<ReadListMethodName>>" method="post" action="#">
<h1>List</h1>
<div>
<%
    if (0 == list.Count)
    {        
%>
    <p> 
        <span class="h1">没有找到您请求的文章！可能原因：</span>
        <ul>
            <li>博主还没有发表过文章</li>
            <li>没有与您输入的搜索条件匹配的文章</li>
        </ul>
    </p>
<%
    }
    else
    {
%>
        <ul>
        <li>
            <span class="previewAll" title="预览全部">预览全部</span>
            <% if(this.IsMaintainMode){ %>
                <input name="checkAll" type="checkbox" value="" />全选
                <button name="del">删除</button>
                <button name="move">移动</button>
            <% }%>
        </li>
<%
        foreach (<<EntityClassName>> info in list)
        {
%>
        <li>
            <span><%if (this.IsMaintainMode){ %><input name="Ids" type="checkbox" value="<%=info.Id %>" /><%} %></span>
            <span class="showHiddenSummary">预览</span>
            <span class="h3"><a href="ArticleDetail.aspx?ArticleId=<%=info.Id %>"><%=info.Title %></a></span>
            <% if(!info.IsPublished){ %><span>※</span><% }%>
            <h3 style="display:none"><%=info.Title %></h3><!--SEO-->
            
            <div class="hiddenSummary">
                <p><%=info.Summary %></p>
                <p><span class="left"><img src="img/icon2.gif" />&nbsp;<a href="ArticleDetail.aspx?ArticleId=<%=info.Id %>">查看更多...</a></span>
                   <span class="right">作者：<%=info.Author %> &nbsp;|&nbsp; 
                                         分类：<a href="#<%=info.CategoryId %>"><%=info.CategoryTitle %></a> &nbsp;|&nbsp; 
                                         查看：<%=info.VisitedCount %> &nbsp;|&nbsp; 
                                         评论：<%=info.CommentsCount %></span></p>
            </div>
            <div class="clear2"></div>
        </li>
<% 
        }
        Response.Write("</ul>");
        Response.Write("<div class='green-black'>");
        MAF.Common.WebPageNavigator pg = new MAF.Common.WebPageNavigator(page, Request.QueryString);
        Response.Write(pg.ToString());
        Response.Write("</div>");
    }
%>
</div>
</form>

<%if (this.IsMaintainMode){ %>
    <ul id="MoveArticleUi" style="display:none">
        <li>
            <label>CategoryId:</label><input type="text" class="CategoryId" readonly="readonly" />
                                      <input type="hidden" name="CategoryId" />
        </li>
        <button>提交</button>
    </ul>
<%} %>
    
<script type="text/javascript">

$(function(){

<%if (this.IsMaintainMode){ %>

    var frm = $("#FrmListArticles");
    
    // 绑定全选事件
    frm.find('input[name="checkAll"]').click(function(){
        frm.find('input[name="Ids"]').attr('checked', $(this).attr('checked') );
    });

    // 绑定提交事件
    frm.ajaxSubmit( function(dat){
        $('body').alert(dat.success||dat.failure||"");
        if(dat.success){
            frm.parent().load('subpages/ArticleList.aspx?<%=Request.QueryString %>');
        }
    });
        
    //
    // 删除文章
    //        
    // 确认删除
    frm.find('button[name="del"]').click(function(){

        $('body').confirm('删除文章','确定要删除选中的文章？',function(){
            frm.attr('action','<%=this.RootUrl %>/blog.aspx?op=DeleteArticles');
            frm.submit();
            frm.attr('action','#');  //防止影响到移动变删除
        });
        
        return false;
    });

    //
    // 移动文章
    //  
    
    var moveUi = $('#MoveArticleUi');
    moveUi.find('button').click(function(){
        frm.submit();
    });
        
    // 弹出移动对话框
    frm.find('button[name="move"]').click(function(){
        
        // 移动
        frm.attr('action','<%=this.RootUrl %>/blog.aspx?op=MoveArticleTo');
        
        // 弹出对话框
        $('body').Dialog('MoveArticleDialog',{title:'移动文章',content:moveUi,masked:'body'},function(){

            moveUi.css({display:'block',border:'1px solid #000'});    
            // 绑定分类选择事件
            var ctrl = moveUi.find('.CategoryId');
            var panel = $('#categoryOptionsBase');
            var valField = moveUi.find('[name=CategoryId]');
            valField.appendTo(frm);
            
            var dds = new jqDropDownSelector( ctrl,panel,function(){
                panel.find('a').click(function(){
                    ctrl.val($(this).text());
                    valField.val( this.hash.replace('#','') );
                    dds.closePanel();
                });
            });
        });
        return false;
    });

    
    
<%} %> 
    // 绑定显示文章概要
    var showHandlers = $('.showHiddenSummary');
    var panels = $('.hiddenSummary');
    
    // 单个预览
    showHandlers.each(function(i){
        $(showHandlers[i]).click(function(){
            $(panels[i]).slideToggle('normal',function(){});
        });
    });
    
    // 反向显示或关闭文章概要(即开闭反转)
    $('.previewAll').click(function(){
        panels.slideToggle('normal',function(){});
    });
});

</script>
